package com.bocloud.cmp.dao.utils;

import java.util.ArrayList;
import java.util.List;

import com.bocloud.cmp.entity.resource.HostPerf;
import com.bocloud.cmp.model.MonitorCategoryModel;
import com.bocloud.cmp.model.MonitorModel;
//import com.google.common.collect.Lists;
import com.bocloud.common.utils.DateTool;

public class MonitorConvert {
    /**
     * 性能数据格式转换
     * 
     * @param herfModel
     * @return
     */
    public MonitorModel convertList(List<HostPerf> herfModels, String type) {
        List<String> keys = new ArrayList<String>();
        MonitorModel monitorModel = new MonitorModel();
        List<MonitorCategoryModel> monitorCatagoryModelList = new ArrayList<MonitorCategoryModel>();
        MonitorCategoryModel monitorCategoryModelcpu = new MonitorCategoryModel();
        MonitorCategoryModel monitorCategoryModelmem = new MonitorCategoryModel();
        MonitorCategoryModel monitorCategoryModeldisk = new MonitorCategoryModel();
        // MonitorCategoryModel monitorCategoryModelmem = new
        // MonitorCategoryModel();
        List<String> cpus = new ArrayList<String>();
        List<String> mems = new ArrayList<String>();
        List<String> disks = new ArrayList<String>();

        for (HostPerf herfModel : herfModels) {
            keys.add(DateTool.formatTime(herfModel.getGmtCreate()));
            cpus.add(herfModel.getCpuUtil().toString());
            mems.add(herfModel.getMemUtil().toString());
            if (null == herfModel.getDiskUtil()) {// 如果为空就是null
                disks.add("0");
            } else {
                disks.add(herfModel.getDiskUtil().toString());
            }
        }
        monitorCategoryModelcpu.setName("CPU");
        monitorCategoryModelcpu.setData(cpus);
        monitorCategoryModelmem.setName("MEM");
        monitorCategoryModelmem.setData(mems);
        monitorCategoryModeldisk.setName("DISK");
        monitorCategoryModeldisk.setData(disks);
        if ("CPU".equalsIgnoreCase(type)) {
            monitorCatagoryModelList.add(monitorCategoryModelcpu);
        } else if ("MEM".equalsIgnoreCase(type)) {
            monitorCatagoryModelList.add(monitorCategoryModelmem);
        } else if ("DISK".equalsIgnoreCase(type)) {
            monitorCatagoryModelList.add(monitorCategoryModeldisk);
        }

        monitorModel.setKeys(keys);

        monitorModel.setValues(monitorCatagoryModelList);
        return monitorModel;
    }

}
